package com.ttg.common.entities;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ttg.common.enums.ErrorCodeEnums;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author h
 * @version 1.0
 * @Description 公共返回模型
 * @date 2023/07/05 14:52:11
 */
@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BaseResult<T> {
    private String errcode;
    private String msg;
    private T data;
    private String sign;
    private Integer timestamp;
    public BaseResult(String errcode, String message){
        this.errcode = errcode;
        this.msg = message;
    }
    public BaseResult(String errcode, String message, T data){
        this.errcode = errcode;
        this.msg = message;
        this.data = data;
    }

    public BaseResult(String errcode, String message, T data,String sign){
        this.errcode = errcode;
        this.msg = message;
        this.data = data;
        this.sign = sign;
    }

    public BaseResult(String errcode, String message, T data, String sign, Integer timestamp){
        this.errcode = errcode;
        this.msg = message;
        this.data = data;
        this.sign = sign;
        this.timestamp = timestamp;
    }

    /**
     * 成功
     * @param data
     * @return
     */
    public static BaseResult success(Object data){
        return new BaseResult(ErrorCodeEnums.SUCCESS.getErrcode(),ErrorCodeEnums.SUCCESS.getMsg(),data);
    }

    public static BaseResult success(Object data, Integer timestamp, String sign){
        return new BaseResult(
                ErrorCodeEnums.SUCCESS.getErrcode(),
                ErrorCodeEnums.SUCCESS.getMsg(),
                data,
                sign,
                timestamp
        );
    }

    public static BaseResult success(Object data, String sign){
        return new BaseResult(
                ErrorCodeEnums.SUCCESS.getErrcode(),
                ErrorCodeEnums.SUCCESS.getMsg(),
                data,
                sign
        );
    }

    /**
     * 返回默认失败（系统异常）
     * @return
     */
    public static BaseResult defaultFail(){
        return new BaseResult(ErrorCodeEnums.SYSTEM_ERROR.getErrcode(),ErrorCodeEnums.SYSTEM_ERROR.getMsg());
    }
}
